<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/8/22
 * Time: 15:54
 */
namespace app\api\controller;

use think\Db;
use think\Exception;
use think\cache\driver\Redis;

/**
 * @package app\api\controller
 * 快三彩种玩法
 * 18：和值，17：三连号，16：三同号，15：三不同号,14:二同号，13：二不同号
 * 返回结果：
 * 和值105：单或18
 * 二同号复选100：11* 22* 33*
 * 三连号通选104：123 234 345 456
 * 三同号单选102：222 444
 * 三同号通选103：111 222 333 444 555 666
 * 二不同号拖胆98：1 , 2或3 , 2 4 5
 * 三不同号拖胆290：1 3, 2 4 5
 */
header("ACCESS-CONTROL-ALLOW-ORIGIN:http://114.215.68.205");

class Play extends Base{

    //18：和值：大，小，单，双，3-18
    private static $hz = [976,977,978,979,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122];
    //15：三不同号
    private static $sbth = [1029];
    //13：二不同号
    private static $ebth = [100];
    //16：三同号
    private static $sth = [105,104];
    //14：二同号
    private static $eth = [102];
    //17：三连号
    private static $slh = [106];

    private static $code = [0,1,2,3,4,5,6,7,8,9];
    private static $code_sum = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27];
    private static $code_sum2 = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18];
    private static $code_position = ["万位","千位","百位","十位","个位"];
    private static $code_model = ["龙","虎","和"];
    private static $code_model2 = ["大","小","单","双"];
    private static $code_model3 = ["豹子","顺子","对子","半顺","杂六"];
    private static $code_model4 = ["牛牛","牛九","牛八","牛七","牛六","牛五","牛四","牛三","牛二","牛一","无牛"];

    private static $lhc_side = ['特单','特双','特大','特小','特合单','特合双','特合大','特合小','特尾大','特尾小','特天肖','特地肖','特前肖','特后肖','特家肖','特野肖','总单','总双','总大','总小'];
    private static $lhc_code = ['01','02','03','04','05','06','07','08','09','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31','32','33','34','35','36','37','38','39','40','41','42','43','44','45','46','47','48','49'];
    private static $lhc_code_spec = ['01','02','03','04','05','06','07','08','09','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31','32','33','34','35','36','37','38','39','40','41','42','43','44','45','46','47','48','49','大','小','单','双','合大','合小','合单','合双','尾大','尾小','尾单','尾双'];
    private static $lhc_code_spec_b = ['01','02','03','04','05','06','07','08','09','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31','32','33','34','35','36','37','38','39','40','41','42','43','44','45','46','47','48','49','大','小','单','双','合大','合小','合单','合双','尾大','尾小','尾单','尾双','红波','蓝波','绿波'];
    private static $lhc_code_square = ['01','02','03','04','05','06','07','08','09','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31','32','33','34','35','36','37','38','39','40','41','42','43','44','45','46','47','48','49','大','小','单','双','合大','合小','合单','合双','尾大','尾小','尾单','尾双','红波','蓝波','绿波','鼠','牛','虎','兔','龙','蛇','马','羊','猴','鸡','狗','猪'];
    private static $lhc_zm = ['正码一','正码二','正码三','正码四','正码五','正码六'];
    private static $lhc_zm_code = ['单','双','大','小','合单','合双','合大','合小','尾大','尾小','红波','绿波','蓝波'];
    private static $lhc_zm_code2 = ['单','双','大','小','合单','合双','合大','合小','尾大','尾小','尾单','尾双','红波','绿波','蓝波'];
    private static $lhc_sx = ['鼠','牛','虎','兔','龙','蛇','马','羊','猴','鸡','狗','猪'];
    private static $lhc_sx2 = ['234肖','5肖','6肖','7肖','总肖单','总肖双'];
    private static $lhc_ssb = ['红波','蓝波','绿波'];
    private static $lhc_bb = ['红单','红双','红大','红小','绿单','绿双','绿大','绿小','蓝单','蓝双','蓝大','蓝小'];
    private static $lhc_bbb = ['红大单','红大双','红小单','红小双','绿大单','绿大双','绿小单','绿小双','蓝大单','蓝大双','蓝小单','蓝小双'];
    private static $lhc_qsb = ['红波','蓝波','绿波','和局'];
    private static $lhc_tws = ['0头','1头','2头','3头','4头','尾0','尾1','尾2','尾3','尾4','尾5','尾6','尾7','尾8','尾9'];
    private static $lhc_ztws = ['0尾','1尾','2尾','3尾','4尾','5尾','6尾','7尾','8尾','9尾'];
    private static $lhc_qm = ["单0.双7","大0.小7","单1.双6","大1.小6","单2.双5","大2.小5","单3.双4","大3.小4","单4.双3","大4.小3","单5.双2","大5.小2","单6.双1","大6.小1","单7.双0","大7.小0"];
    private static $lhc_wx = ["金","木","水","火","土"];
    private static $lhc_sum = ['总和大','总和小','总和单','总和双'];

    public function index(){

        $czid = input("czid",0);
        $ret = array(
            'result'=>0,
            'ResultMsg' => ''
        );
        if( empty($czid) ){
            $ret['ResultMsg'] = '请求参数错误';
            return json_encode($ret,JSON_UNESCAPED_UNICODE);
        }
        $this->qihaoNext($czid);
        $current = $history = [];
        //下期开奖信息
        $redis = new Redis();
        $next_redis = $redis->get($czid);
        if( $next_redis ){
            $next_arr = explode(',', $next_redis);
            $current['next_no'] = $next_arr[0];
            $current['next_time'] = $next_arr[1];
        }else{
            $next_detail = Db::name('kjjg_list')->where(['czid'=>$czid,'kjjg'=>0])->order('jztime','DESC')->find();
            if( $next_detail ){
                $current['next_no'] = $next_detail['qihao'];
                $current['next_time'] = $next_detail['jztime'];
            }
        }
//        $fp_time = Db::name('caipai_list')->where(['id'=>$czid])->value('cp_fp_time');
//        if(isset($current['next_time'])) $current['next_time'] = intval($current['next_time'])-intval($fp_time);
        //获取最新一期的上一期期号(不管有无结果)
        $before_redis = $redis->get('secend_'.$czid);
        if($before_redis) {
            $current['before_no'] = $before_redis;
        }else{
            $current['before_no'] = Db::name('kjjg_list')->where('czid',$czid)->where('jztime','<',time())->order('jztime','DESC')->value('qihao');
        }
        //获得有结果的最新开奖信息
        $current_redis = $redis->get('result_'.$czid);
        if( $current_redis ){
            $current_arr = explode(',', $current_redis);
            $current_kjjg = trim($current_arr[2]);
            $current['current_no'] = $current_arr[0];
            $current['current_time'] = $current_arr[1];
        }else{
            $current_detail = Db::name('kjjg_list')->where('czid',$czid)->where('jztime','<',time())->where('kjjg','<>','0')->order('jztime','DESC')->find();
            $current_kjjg = trim($current_detail['kjjg']);
            $current['current_no'] = $current_detail['qihao'];
            $current['current_time'] = $current_detail['jztime'];
        }
        $current['current_kjjg'] = [];
        $current['current_sum'] = '';
        $current['current_dx'] =  '';
        $current['current_ds'] = '';
        if( $current_kjjg ){
            $current['current_kjjg'] = str_split( $current_kjjg );
            $current['current_sum'] = array_sum($current['current_kjjg']).'';
            $current['current_dx'] =  $current['current_sum'] > 10 ? '大' : '小';
            $current['current_ds'] = ( 0==intval($current['current_sum'])%2 ) ? '双' : '单';
        }
        $current['amount'] = Db::name("time")->where(['czid'=>$czid,'jztime'=>['>=',date('H:i:s',time())]])->count();

        $list = Db::name('kjjg_list')->where('czid',$czid)->where('kjjg','<>','0')->field("qihao,kjjg,jztime")->order('jztime','DESC')->paginate(10)->each(function($v){
            $v['no'] = $v['qihao'];
            $v['kjjg'] = str_split($v['kjjg']);
            $v['sum'] = array_sum( $v['kjjg'] ).'';
            $v['dx'] = $v['sum'] > 10 ? '大' : '小';
            $v['ds'] = ( 0==intval($v['sum'])%2 ) ? '双' : '单';
            unset($v['qihao']);
            return $v;
        })->toArray();
        $list && $list = $list['data'];

        $ret['result'] = 1;
        $ret['datas'] = [
            'current' => $current,
            'history' => $list
        ];
        return json_encode($ret,JSON_UNESCAPED_UNICODE);
    }
    public function nextPeriod(){
        $czid = input("czid",0);
        $ret = array(
            'result'=>0,
            'ResultMsg' => ''
        );
        if( empty($czid) ){
            $ret['ResultMsg'] = '请求参数错误';
            return json_encode($ret,JSON_UNESCAPED_UNICODE);
        }
        $this->qihaoNext($czid);
        $redis = new Redis();
        $next_redis = $redis->get($czid);

        $amount = Db::name("time")->where(['czid'=>$czid,'jztime'=>['>=',date('H:i:s',time())]])->count();
        $datas = ['next_no'=>'','next_time'=>0,'amount'=>$amount];
        if( $next_redis ){
            $next_arr = explode(',', $next_redis);
            $datas['next_no'] = $next_arr[0];
            $datas['next_time'] = $next_arr[1];
        }else{
            $next_detail = Db::name('kjjg_list')->where(['czid'=>$czid,'kjjg'=>0])->field("qihao,kjjg,jztime")->order('jztime','DESC')->find();
            if( $next_detail ){
                $datas['next_no'] = $next_detail['qihao'];
                $datas['next_time'] = $next_detail['jztime'];
            }
        }
//        $fp_time = Db::name('caipai_list')->where(['id'=>$czid])->value('cp_fp_time');
//        if(!empty($datas['next_time'])) $datas['next_time'] = intval($datas['next_time'])-intval($fp_time);

        $ret['result'] = 1;
        $ret['datas'] = $datas;
        return json_encode($ret,JSON_UNESCAPED_UNICODE);
    }
    public function currentPeriod(){

        $czid = input("czid",0);
        $ret = array(
            'result'=>0,
            'ResultMsg' => ''
        );
        if( empty($czid) ){
            $ret['ResultMsg'] = '请求参数错误';
            return json_encode($ret,JSON_UNESCAPED_UNICODE);
        }
        $this->qihaoNext($czid);
        $redis = new Redis();
        $before_redis = $redis->get('secend_'.$czid);
        if($before_redis) {
            $detail = Db::name('kjjg_list')->where(['czid'=>$czid,'qihao'=>$before_redis])->field("qihao,kjjg,jztime")->find();
        }else{
            $detail = Db::name('kjjg_list')->where('czid',$czid)->where('jztime','<',time())->field("qihao,kjjg,jztime")->order('jztime','DESC')->find();
        }
        if( empty($detail) ){
            $ret['ResultMsg'] = '暂无开奖信息';
            return json_encode($ret,JSON_UNESCAPED_UNICODE);
        }
        if( "0"!=$detail['kjjg'] ){
            $detail['kjjg'] = str_split($detail['kjjg']);
            $detail['sum'] = array_sum( $detail['kjjg'] ).'';
            $detail['dx'] = $detail['sum'] > 10 ? '大' : '小';
            $detail['ds'] = ( 0==intval($detail['sum'])%2 ) ? '双' : '单';
        }else{
            $detail['kjjg'] = [];
            $detail['sum'] = '';
            $detail['dx'] = '';
            $detail['ds'] = '';
        }
        $ret['result'] = 1;
        $ret['datas'] = $detail;
        return json_encode($ret,JSON_UNESCAPED_UNICODE);
    }
    public function nowTime(){
        $ret = array(
            'result'=>1,
            'datas' => time()
        );
        return json_encode($ret,JSON_UNESCAPED_UNICODE);
    }
    public function timeList(){
        $czid = input("czid",0);
        $ret = array(
            'result'=>0,
            'ResultMsg' => ''
        );
        if( empty($czid) ){
            $ret['ResultMsg'] = '请求参数错误';
            return json_encode($ret,JSON_UNESCAPED_UNICODE);
        }
        $lower = [5,7,9,51];
        $result = [];
        $fp_time = Db::name("caipai_list")->where(['id'=>$czid])->value("cp_fp_time");
        $previous = Db::name('kjjg_list')->where(['czid'=>$czid,'jztime'=>['<',time()]])->order('qihao','DESC')->find();

        $previous['qihao'] = $this->getTheoryPrevious($czid,$previous['qihao'],$previous['jztime'],$fp_time);
        $this->redis->set("secend_{$czid}", "{$previous['qihao']}");

        if( !in_array($czid,$lower) ){
            //每天多期数据
            $tm = date('H:i:s',time() + $fp_time + 10);

            $time_list_day = Db::name("time")->where(['czid'=>$czid,'jztime'=>['>',$tm]])->field("qihao,jztime,1 as type")->order("jztime ASC")->limit(5)->select();
            if( count($time_list_day) < 5 ){
                $time_list_next = Db::name("time")->where(['czid'=>$czid])->field("qihao,jztime,2 as type")->order("jztime ASC")->limit(5-count($time_list_day))->select();
                $time_list = array_merge($time_list_day,$time_list_next);
            }else{
                $time_list = $time_list_day;
            }
            $i = 0;
            foreach($time_list as $k=>$v){
                switch ( intval($czid) ) {
                    case 1:
                        ///重庆时时彩
                        $v['qihao'] = intval($v['qihao']) < 10 ? '00'.$v['qihao'] : ( intval($v['qihao']) < 100 ? '0'.$v['qihao']: $v['qihao'] );
                        if( 120 == intval($v['qihao'])){
                            $v['qihao'] = date('Ymd',time()).$v['qihao'];
                            $v['jztime'] = strtotime(date("Y-m-d",strtotime("+1 day")) . ' ' . $v['jztime']);
                        }elseif(1==$v['type']){
                            $v['qihao'] = date('Ymd',time()).$v['qihao'];
                            $v['jztime'] = strtotime(date("Y-m-d",time()) . ' ' . $v['jztime']);
                        }else{
                            $v['qihao'] = date("Ymd",strtotime("+1 day")).$v['qihao'];
                            $v['jztime'] = strtotime(date("Y-m-d",strtotime("+1 day")) . ' ' . $v['jztime']);
                        }
                        break;
                    case 62:
                        //分分时时彩
                        if ( (0==intval($v['qihao']) && $v['jztime'] = '00:00:00') || 2==$v['type'] ) {
                            $v['qihao'] = date('YmdHi', strtotime(date('Y-m-d', strtotime('+1 day')) . $v['jztime']));
                            $v['jztime'] = strtotime(date("Y-m-d",strtotime("+1 day")) . ' ' . $v['jztime']);
                        }else {
                            $v['qihao'] = date('YmdHi', strtotime(date('Y-m-d', time()) . $v['jztime']));
                            $v['jztime'] = strtotime(date("Y-m-d",time()) . ' ' . $v['jztime']);
                        }
                        break;
                    case 63:
                        //极速PK10
                    case 72:
                        //极速快三
                        if( 1==strlen($v['qihao']) ){
                            $v['qihao'] = '000'.$v['qihao'];
                        }elseif( 2==strlen($v['qihao']) ){
                            $v['qihao'] = '00'.$v['qihao'];
                        }elseif( 3==strlen($v['qihao']) ){
                            $v['qihao'] = '0'.$v['qihao'];
                        }
                        if( (1440==intval($v['qihao']) && $v['jztime'] = '00:00:00')){
                            $v['qihao'] = date('Ymd').$v['qihao'];
                            $v['jztime'] = strtotime(date("Y-m-d",strtotime('+1 day')) . ' ' . $v['jztime']);
                        }elseif(1==$v['type']){
                            $v['qihao'] = date('Ymd').$v['qihao'];
                            $v['jztime'] = strtotime(date("Y-m-d",time()) . ' ' . $v['jztime']);
                        }else{
                            $v['qihao'] = date('Ymd',strtotime('+1 day')).$v['qihao'];
                            $v['jztime'] = strtotime(date("Y-m-d",strtotime('+1 day')) . ' ' . $v['jztime']);
                        }
                        break;
                    case 36://安徽快三
                    case 39://甘肃快3  gsk3
                    case 40://广西快3  gxk3
                    case 41://贵州快3  gzk3
                    case 43://湖北快3  hubk3
//                case 46://吉林快3
                    case 47://上海快3  shk3
                    case 44://江苏快三
                    case 8: //天津时时彩彩
                    case 73: //五分六合彩
                        $v['qihao'] = intval($v['qihao']) < 10 ? '00'.$v['qihao'] : ( intval($v['qihao']) < 100 ? '0'.$v['qihao']: $v['qihao'] );
                        if(1==$v['type']){
                            $v['qihao'] = date('Ymd').$v['qihao'];
                            $v['jztime'] = strtotime(date("Y-m-d",time()) . ' ' . $v['jztime']);
                        }else{
                            $v['qihao'] = date('Ymd',strtotime('+1 day')).$v['qihao'];
                            $v['jztime'] = strtotime(date("Y-m-d",strtotime('+1 day')) . ' ' . $v['jztime']);
                        }
                        break;
                    case 4:
                        ///北京赛车
                    case 10:
                        ///PC蛋蛋
                        ++$i;
                        $v['qihao'] = strval( intval($previous['qihao'])+$i );
                        if(1==$v['type']){
                            $v['jztime'] = strtotime( date("Y-m-d",time()) . ' ' . $v['jztime']);
                        }else{
                            $v['jztime'] = strtotime( date("Y-m-d",strtotime('+1 day')) . ' ' . $v['jztime']);
                        }
                        break;
                    case 16:
                        //广东11选5
                    case 28:
                        //山东11选5
                    case 29:
                        //上海11选5
                    case 48:
                        ///上海时时乐
                    case 25:
                        //江西11选5
                        $v['qihao'] = intval($v['qihao']) < 10 ? '0'.$v['qihao'] : $v['qihao'];
                        if(1==$v['type']){
                            $v['jztime'] = strtotime(date("Y-m-d",time()) . ' ' . $v['jztime']);
                            $v['qihao'] = date('Ymd') . $v['qihao'];
                        }else{
                            $v['jztime'] = strtotime(date("Y-m-d",strtotime('+1 day')) . ' ' . $v['jztime']);
                            $v['qihao'] = date("Ymd",strtotime('+1 day')) . $v['qihao'];
                        }
                        break;
                    case 61:
                        //幸运飞艇
                        $v['qihao'] = intval($v['qihao']) < 10 ? '00'.$v['qihao'] : ( intval($v['qihao']) < 100 ? '0'.$v['qihao']: $v['qihao'] );
                        if(1==$v['type']){
                            $v['jztime'] = strtotime(date("Y-m-d",time()) . ' ' . $v['jztime']);
                            if( intval($v['qihao']) > 131 ){
                                $v['qihao'] = date("Ymd",strtotime('-1 day')) . $v['qihao'];
                            }else{
                                $v['qihao'] = date('Ymd') . $v['qihao'];
                            }
                        }else{
                            $v['jztime'] = strtotime(date("Y-m-d",strtotime('+1 day')) . ' ' . $v['jztime']);
                            $v['qihao'] = date('Ymd') . $v['qihao'];
                        }
                        break;
                    case 2:
                        //新疆时时彩
                        $v['qihao'] = str_pad($v['qihao'],3,"0",STR_PAD_LEFT);
                        if(1==$v['type']){
                            $v['jztime'] = strtotime(date("Y-m-d",time()) . ' ' . $v['jztime']);
                            if( intval($v['qihao']) >= 84 ){
                                $v['qihao'] = date("Ymd",strtotime('-1 day')) . $v['qihao'];
                            }else{
                                $v['qihao'] = date('Ymd') . $v['qihao'];
                            }
                        }else{
                            $v['jztime'] = strtotime(date("Y-m-d",strtotime('+1 day')) . ' ' . $v['jztime']);
                            $v['qihao'] = date('Ymd') . $v['qihao'];
                        }
                        break;
                }
                unset($v['type']);
                isset($v['jztime']) && $v['jztime'] -= $fp_time;
                0==intval($k) && $this->redis->set("{$czid}", "{$v['qihao']},{$v['jztime']},0");
                $result[] = $v;
            }
        }else{
            $time_list_day = Db::name("time")->where(['czid'=>$czid])->field("qihao,jztime")->find();
            $open_time = strtotime(date('Y-m-d',time()).' '.$time_list_day['jztime']);
            //低频彩5,7,9,51
            $data = [];
            switch(intval($czid)){
                case 5:
                    //排列三
                case 7:
                    //福彩3D
                    $data['qihao'] = strval( intval($previous['qihao'])+1 );
                    if( time() + $fp_time < $open_time ){
                        $data['jztime'] = $open_time - $fp_time;
                    }else{
                        $data['jztime'] = strtotime(date("Y-m-d",strtotime("+1 day")) . ' ' . $time_list_day['jztime']) - $fp_time;
                    }
                    $result[] = $data;
                    break;
                case 9:
                    //香港六合彩
                    if( time() < strtotime(date('Y-m-d 21:30:00')) ){
                        $calc_time = strtotime('-1 day');
                    }else{
                        $calc_time = time();
                    }
                    $week = date("w", $calc_time);
                    if ($week == '2' || $week == '4' || $week == '0') {   //星期2,4 日+2天
                        $data['jztime'] = strtotime(date('Y-m-d', $calc_time + 2 * 24 * 3600) . ' ' . $time_list_day['jztime']) - $fp_time;
                    }
                    if ($week == '6') {   //星期6+3天
                        if((11==intval(date('m',$calc_time)) && 10==intval(date('d',$calc_time))) || (12==intval(date('m',$calc_time)) && 29==intval(date('d',$calc_time)))){
                            $data['jztime'] = strtotime(date('Y-m-d', $calc_time + 1 * 24 * 3600) . ' ' . $time_list_day['jztime']) - $fp_time;
                        }else{
                            $data['jztime'] = strtotime(date('Y-m-d', $calc_time + 3 * 24 * 3600) . ' ' . $time_list_day['jztime']) - $fp_time;
                        }
                    }
                    if ($week == '1' || $week == '3' || $week == '5') {   //星期1,3,5+1天
                        $data['jztime'] = strtotime(date('Y-m-d', $calc_time + 1 * 24 * 3600) . ' ' . $time_list_day['jztime']) - $fp_time;
                    }
                    $data['qihao'] = strval( intval($previous['qihao'])+1 );
                    $result[] = $data;
                    $result[] = self::lhcTimeList($data['jztime'],$data['qihao'],$fp_time);
                    break;
                case 51:
                    //七星彩
                    if( time() < strtotime(date('Y-m-d 20:30:00')) ){
                        $week = date("w", strtotime('-1 day'));
                    }else{
                        $week = date("w", time());
                    }
                    if ($week == '3' || $week == '5' || $week == '0') {   //星期3+2天
                        $data['jztime'] = strtotime(date('Y-m-d', time() + 2 * 24 * 3600) . ' ' . $time_list_day['jztime']) - $fp_time;
                    }
                    if ($week == '2') {   //星期2+3天
                        $data['jztime'] = strtotime(date('Y-m-d', time() + 3 * 24 * 3600) . ' ' . $time_list_day['jztime']) - $fp_time;
                    }
                    if ($week == '1' || $week == '4' || $week == '6') {   //星期4,6+1天
                        $data['jztime'] = strtotime(date('Y-m-d', time() + 1 * 24 * 3600) . ' ' . $time_list_day['jztime']) - $fp_time;
                    }
                    $data['qihao'] = strval( intval($previous['qihao'])+1 );
                    $result[] = $data;
                    break;
            }
            $this->redis->set("{$czid}", "{$data['qihao']},{$data['jztime']},0");
        }
        if(empty($result)){
            $ret['ResultMsg'] = '暂无数据';
        }else{
            $ret['result'] = 1;
            $ret['datas'] = $result;
        }
        return json_encode($ret,JSON_UNESCAPED_UNICODE);
    }
    public function odds(){
        $id = input("id",0);
        $ret = array(
            'result'=>0,
            'ResultMsg' => ''
        );
        if( empty($id) ){
            $ret['ResultMsg'] = '传入信息错误';
            return json_encode($ret,JSON_UNESCAPED_UNICODE);
        }
        $classify = Db::name('play_classify')->where(['way_class_id'=>$id,'open'=>1])->value("GROUP_CONCAT(peilv_ids) as ids");
        $peilv = Db::name("peilv")->where("id in ($classify)")->column("id,zgpl,peilv_name");
        $search = [];
        switch( intval($id) ){
            case 18;
                $search = self::$hz;
                break;
            case 15:
                $search = self::$sbth;
                break;
            case 13:
                $search = self::$ebth;
                break;
            case 16:
                $search = self::$sth;
                break;
            case 14:
                $search = self::$eth;
                break;
            case 17:
                $search = self::$slh;
                break;
        }
        $peilvAttr = [];
        foreach( $search as $v ){
            isset($peilv[$v]) && $peilvAttr[] = $peilv[$v]['zgpl'];
        }
        $ret['result'] = 1;
        $ret['datas'] = $peilvAttr;
        return json_encode($ret,JSON_UNESCAPED_UNICODE);
    }
    public function bet(){
        //投注号码[G]元角分[G]金额[G]注数[G]单注金额[G]最高赔率[G]返点值[G]玩法ID[G]赔率ID[H]
        //投注号码[G]元角分[G]金额[G]注数[G]单注金额[G]最高赔率[G]返点值[G]玩法ID[G]赔率ID
        //组合投注  赔率：97000.00|9700.00|970.00|97.00|9.70|，赔率ID：同样按|分割
        //多赔率的玩法：五星直选组合,后四直选组合,前四直选组合,三中二,二中特
        //赔率可变：正码过关173，合肖242
        //十一选五：两面盘，1-5球
        $post = input('post.');
        $czid = isset($post['czid']) ? $post['czid'] : 0;
        $number = $number_original = isset($post['number']) ? $post['number'] : '';
        $periods = isset($post['qihao']) ? $post['qihao'] : '';
        $name = isset($post['name']) ? $post['name'] : '';
        $from = isset($post['from']) ? $post['from'] : 0;
        $mdstr = isset($post['str']) ? $post['str'] : '';
        $key = 'bs0uoirk';
        $ret = array(
            'result'=>0,
            'ResultMsg' => ''
        );
        $number_yanz = md5($number.$key);
        if($number_yanz != $mdstr){
            $ret['ResultMsg'] = '下注失败请重试';
            $this->weigui_touzhu($name,$number_original,$periods,$czid,'投注串被创改',$from);
            return json_encode($ret,JSON_UNESCAPED_UNICODE);
        }
        if(empty($name)){
            $ret['ResultMsg'] = '未传入用户参数';
            return json_encode($ret,JSON_UNESCAPED_UNICODE);
        }
        $login_key = input('login_key', '');
        $user = Db::name('username')->where(['username'=>$name,'login_key'=>$login_key])->where('open', '<', 1)->find();
        if(empty($user)){
            $ret['ResultMsg'] = '用户信息错误';
            return json_encode($ret,JSON_UNESCAPED_UNICODE);
        }
        if( 1==intval($user['touzhu_open']) ){
            $ret['ResultMsg'] = '未开通投注权限';
            return json_encode($ret,JSON_UNESCAPED_UNICODE);
        }
        if( empty($czid) || empty($number) || empty($periods) || empty($from) ) {
            $ret['ResultMsg'] = '投注数据有误';
            $this->weigui_touzhu($name,$number_original,$periods,$czid,'参数不完整',$from);
            return json_encode($ret,JSON_UNESCAPED_UNICODE);
        }
        //验证是否有效期号
        $next = $this->qihaoNext($czid);
        if( $next != $periods ){
            $ret['ResultMsg'] = '期号有误，请重新投注！';
            return json_encode($ret,JSON_UNESCAPED_UNICODE);
        }
        /* 验证投注号码格式是否正确 */
        $number = explode('[H]',trim($number,'[H]'));
        if( !empty($number) ){
            $total_money = 0;
            //查询当前彩种返点
            $lottery_info = Db::name('lottery_classify')->field('id,fandian')->where("czids REGEXP '(^|,){$czid}($|,)'")->find();
            if( empty($lottery_info) ){
                $ret['ResultMsg'] = '返点信息错误！';
                return json_encode($ret,JSON_UNESCAPED_UNICODE);
            }
            $fandian = floatval($lottery_info['fandian']);
            $save_data = [];
            foreach($number as $val){
                $detail = explode('[G]',$val);
                if( 9==count($detail)) {
                    if(!is_numeric($detail[2])) {
                        $ret['ResultMsg'] = '投注金额错误！';
                        return json_encode($ret,JSON_UNESCAPED_UNICODE);
                    }
                    $total_money += floatval($detail[2]);
                    //查询验证所需信息
                    $checks = Db::name('play_classify_ext')->alias('a')
                        ->join('kkty_play_classify b','a.play_id=b.id','LEFT')
                        ->where(['a.play_id'=>$detail[7],'a.czid'=>$czid,'a.open'=>1])
                        ->field('a.peilv_ids,b.id,b.class_name_mini,b.min_num,b.max_num,b.max_money')
                        ->find();
                    if(empty($checks)){
                        $checks = Db::name('play_classify')->field('id,class_name_mini,min_num,max_num,peilv_ids,max_money')->where('id',$detail[7])->find();
                    }
                    //验证最大投注金额
                    if( $checks['max_money'] ) {
                        $pay_money = floatval($detail[4]);
                        if( '2'==$detail[1] ){
                            $pay_money = floatval($detail[4])/10;
                        }elseif( '3'==$detail[1] ){
                            $pay_money = floatval($detail[4])/100;
                        }
                        if( $pay_money > floatval($checks['max_money']) ){
                            $ret['ResultMsg'] = '超出单注最大投注金额';
                            return json_encode($ret,JSON_UNESCAPED_UNICODE);
                        }
                    }
                    //获取赔率信息
                    $pl_attr = explode('|',trim($detail[5],'|'));
                    $pl_id_attr = explode('|',trim($detail[8],'|'));
                    if( 173 == intval($detail[7]) ){
                        //正码过关
                        if( count($pl_attr) > 1 || empty($pl_attr) ){
                            $ret['ResultMsg'] = '赔率计算错误';
                            $this->weigui_touzhu($name,$number_original,$periods,$czid,'赔率计算错误',$from);
                            return json_encode($ret,JSON_UNESCAPED_UNICODE);
                        }
                        $peilv_true = 1;
                        foreach($pl_id_attr as $k=>$v){
                            $peilv_info = Db::name('peilv')->find($v);
                            $peilv_tmp = $peilv_info['zdpl'] + ( ($peilv_info['zgpl']-$peilv_info['zdpl']) / ($fandian ? $fandian : 1) ) * ($fandian - $detail[6]);
                            $peilv_true *= $peilv_tmp;
                        }
                        if( sprintf('%.2f',$peilv_true) != sprintf('%.2f',$detail[5]) ) {
                            $ret['ResultMsg'] = '赔率计算错误';
                            $this->weigui_touzhu($name,$number_original,$periods,$czid,'赔率计算错误',$from);
                            return json_encode($ret,JSON_UNESCAPED_UNICODE);
                        }
                    }elseif( 242 == intval($detail[7]) ){
                        //合肖
                        if( count($pl_attr) > 1 || empty($pl_attr) ){
                            $ret['ResultMsg'] = '赔率计算错误';
                            $this->weigui_touzhu($name,$number_original,$periods,$czid,'赔率计算错误',$from);
                            return json_encode($ret,JSON_UNESCAPED_UNICODE);
                        }
                        $peilv_true = 0;
                        foreach($pl_id_attr as $k=>$v){
                            $peilv_info = Db::name('peilv')->find($v);
                            $peilv_tmp = $peilv_info['zdpl'] + ( ($peilv_info['zgpl']-$peilv_info['zdpl']) / ($fandian ? $fandian : 1) ) * ($fandian - $detail[6]);
                            $peilv_true += $peilv_tmp;
                        }
                        $peilv_true = $peilv_true / count($pl_id_attr) / count($pl_id_attr);
                        if( sprintf('%.2f',$peilv_true) != sprintf('%.2f',$detail[5]) ) {
                            $ret['ResultMsg'] = '赔率计算错误';
                            $this->weigui_touzhu($name,$number_original,$periods,$czid,'赔率计算错误',$from);
                            return json_encode($ret,JSON_UNESCAPED_UNICODE);
                        }
                    }elseif( 294==intval($detail[7]) || 295==intval($detail[7])|| 297==intval($detail[7]) || 298==intval($detail[7]) ){
                        if( count($pl_attr) !=count($pl_id_attr) || empty($pl_attr)){
                            $ret['ResultMsg'] = '赔率计算错误';
                            $this->weigui_touzhu($name,$number_original,$periods,$czid,'赔率计算错误',$from);
                            return json_encode($ret,JSON_UNESCAPED_UNICODE);
                        }

                        foreach($pl_attr as $k=>$v){
                            $pl_detail = explode(' ',trim($v));
                            $pl_id_detail = explode(' ',trim($pl_id_attr[$k]));
                            if( count($pl_detail) !=count($pl_id_detail) ){
                                $ret['ResultMsg'] = '赔率计算错误';
                                $this->weigui_touzhu($name,$number_original,$periods,$czid,'赔率计算错误',$from);
                                return json_encode($ret,JSON_UNESCAPED_UNICODE);
                            }
                            foreach($pl_id_detail as $key=>$value){
                                if( !empty($value) ){
                                    $peilv_info = Db::name('peilv')->where('id','like',$value)->find();
                                    if(empty($peilv_info)){
                                        $ret['ResultMsg'] = '赔率计算错误';
                                        $this->weigui_touzhu($name,$number_original,$periods,$czid,'赔率计算错误',$from);
                                        return json_encode($ret,JSON_UNESCAPED_UNICODE);
                                    }
                                    $peilv_true = $peilv_info['zdpl'] + ( ($peilv_info['zgpl']-$peilv_info['zdpl']) / ($fandian ? $fandian : 1) ) * ($fandian - $detail[6]);
                                    $peilv_true = sprintf('%.2f',$peilv_true);
                                    if( $peilv_true != sprintf('%.2f',$pl_detail[$key]) ) {
                                        $ret['ResultMsg'] = '赔率计算错误';
                                        $this->weigui_touzhu($name,$number_original,$periods,$czid,'赔率计算错误',$from);
                                        return json_encode($ret,JSON_UNESCAPED_UNICODE);
                                    }
                                }
                            }
                        }
                    }else{
                        if( count($pl_attr) !=count($pl_id_attr) || empty($pl_attr) ){
                            $ret['ResultMsg'] = '赔率计算错误';
                            $this->weigui_touzhu($name,$number_original,$periods,$czid,'赔率计算错误',$from);
                            return json_encode($ret,JSON_UNESCAPED_UNICODE);
                        }
                        foreach($pl_id_attr as $k=>$v){
                            $peilv_info = Db::name('peilv')->where('id','like',$v)->find();
                            if(empty($peilv_info)){
                                $ret['ResultMsg'] = '赔率计算错误';
                                $this->weigui_touzhu($name,$number_original,$periods,$czid,'赔率计算错误',$from);
                                return json_encode($ret,JSON_UNESCAPED_UNICODE);
                            }
                            $peilv_true = $peilv_info['zdpl'] + ( ($peilv_info['zgpl']-$peilv_info['zdpl']) / ($fandian ? $fandian : 1) ) * ($fandian - $detail[6]);
                            $peilv_true = sprintf('%.2f',$peilv_true);
                            if( $peilv_true != sprintf('%.2f',$pl_attr[$k]) ) {
                                $ret['ResultMsg'] = '赔率计算错误';
                                $this->weigui_touzhu($name,$number_original,$periods,$czid,'赔率计算错误',$from);
                                return json_encode($ret,JSON_UNESCAPED_UNICODE);
                            }
                        }
                    }
                    //验证号码是否超限
                    $code = array_map('trim',explode(',',$detail[0]));
                    if( 1==count($code) ){
                        if( is_numeric($code[0]) && (floatval($code[0])<$checks['min_num'] || floatval($code[0])>$checks['max_num'] ) && $checks['max_num'] >0 ){
                            $ret['ResultMsg'] = '号码超出可选范围';
                            $this->weigui_touzhu($name,$number_original,$periods,$czid,'号码超出可选范围',$from);
                            return json_encode($ret,JSON_UNESCAPED_UNICODE);
                        }
                    }else{
                        foreach($code as $v) {
                            if( is_numeric($v) && (floatval($v)<$checks['min_num'] || floatval($v)>$checks['max_num'] ) && $checks['max_num'] >0 ){
                                $ret['ResultMsg'] = '号码超出可选范围';
                                $this->weigui_touzhu($name,$number_original,$periods,$czid,'号码超出可选范围',$from);
                                return json_encode($ret,JSON_UNESCAPED_UNICODE);
                            }
                        }
                    }
                    //验证投注注数
                    $tzzs = touzhu_hm_code_zhushu($detail[7],$detail[0],$lottery_info['id']);
                    if( 0==$tzzs || $tzzs!=$detail[3] ){
                        $ret['ResultMsg'] = '验证投注注数失败';
                        $this->weigui_touzhu($name,$number_original,$periods,$czid,'验证投注注数失败',$from);
                        return json_encode($ret,JSON_UNESCAPED_UNICODE);
                    }
                    array_push($detail,$checks['id']);
                    $save_data[] = $detail;

                }else{
                    $ret['ResultMsg'] = '数据格式错误';
                    return json_encode($ret,JSON_UNESCAPED_UNICODE);
                }
            }

            //验证投注总金额
            $total_theory = $this->calc_money($number_original);
            if( 0==$total_theory ||sprintf("%.2f",$total_theory)!=sprintf("%.2f",$total_money) ){
                $ret['ResultMsg'] = '投注总额验证失败';
                $this->weigui_touzhu($name,$number_original,$periods,$czid,'投注总额验证失败',$from);
                return json_encode($ret,JSON_UNESCAPED_UNICODE);
            }
            //验证用户总金额
            if($user['je'] < $total_money) {
                $ret['ResultMsg'] = '账户金额不足';
                return json_encode($ret,JSON_UNESCAPED_UNICODE);
            }
            Db::startTrans();
            try {
                foreach( $save_data as $data ){
                    //限制返点范围
                    if($data[6] > $fandian) $data[6] = $fandian;
                    if($data[6] < 0) $data[6] = 0;
                    //返点应扣除金额
                    $fandian_je = floatval($data[2]) / 100 * floatval($data[6]);
//                  //计算返点、打码量、投注金额等信息
                    $touzhu_true_je = floatval($data[2]) - $fandian_je;
                    $user['je'] -= floatval( $touzhu_true_je );
                    $user['dml'] -= floatval( $touzhu_true_je );
                    $user['tzzje'] += floatval($touzhu_true_je);
                    $user['zyh_tzzje'] += floatval($touzhu_true_je);
                    //将新投注插入未结算列表
                    if( !model( 'TouzhuListNo' )->setBetInfoNo($czid,$periods,$data[0],$data[2],$data[4],$data[3],$name,$user['je'],0,0,$data[9],$data[5],$data[6],$fandian_je,0,0,$data[1],time(),$from) ){
                        throw new Exception("新投注插入未结算列表失败");
                    }
                }
                $user['dml'] < 0 && $user['dml'] = 0;
                if( !model('Username')->updateUserBetInfo($user['je'],$user['dml'],$user['tzzje'],$name,$user['zyh_tzzje']) ){
                    throw new Exception("更新用户信息失败");
                }
                Db::commit();
                $ret['result'] = 1;
                return json_encode($ret,JSON_UNESCAPED_UNICODE);
            } catch (\Exception $e) {
                Db::rollback();
                $ret['ResultMsg'] = '下注失败请重试';
                return json_encode($ret,JSON_UNESCAPED_UNICODE);
            }
        }else{
            $ret['ResultMsg'] = '数据格式错误';
            return json_encode($ret,JSON_UNESCAPED_UNICODE);
        }
    }
    public function zhuihao(){

        //投注号码[G]元角分[G]金额[G]注数[G]单注金额[G]最高赔率[G]返点值[G]玩法ID[G]赔率ID[G]期号[H]
        //投注号码[G]元角分[G]金额[G]注数[G]单注金额[G]最高赔率[G]返点值[G]玩法ID[G]赔率ID[G]期号
        $post = input('post.');
        $czid = isset($post['czid']) ? $post['czid'] : 0;
        $number = $number_original = isset($post['number']) ? $post['number'] : '';
        $name = isset($post['name']) ? $post['name'] : 0;
        $from = isset($post['from']) ? $post['from'] : 3;
        $isStop = isset($post['isStop']) ? $post['isStop'] : 1; //1:中奖后停止，0：中奖后不停止
        $mdstr = isset($post['str']) ? $post['str'] : '';
        $key = 'bs0uoirk';
        $ret = array(
            'result'=>0,
            'ResultMsg' => ''
        );
        $number_key = md5($number.$key);
        if($number_key != $mdstr){
            $ret['ResultMsg'] = '追号失败';
            $this->weigui_zhuihao($name,$number_original,$czid,'投注串被创改',$from);
            return json_encode($ret,JSON_UNESCAPED_UNICODE);

        }
        if(empty($name)){
            $ret['ResultMsg'] = '未传入用户参数';
            return json_encode($ret,JSON_UNESCAPED_UNICODE);
        }
        $login_key = input('login_key', '');
        $user = Db::name('username')->where(['username'=>$name,'login_key'=>$login_key])->where('open', '<', 1)->find();
        if(empty($user)){
            $ret['ResultMsg'] = '用户信息错误';
            return json_encode($ret,JSON_UNESCAPED_UNICODE);
        }
        if( 1==intval($user['touzhu_open']) ){
            $ret['ResultMsg'] = '未开通投注权限';
            return json_encode($ret,JSON_UNESCAPED_UNICODE);
        }
        if( empty($czid) || empty($number) || empty($from)) {
            $ret['ResultMsg'] = '投注数据有误';
            $this->weigui_zhuihao($name,$number_original,$czid,'参数不完整',$from);
            return json_encode($ret,JSON_UNESCAPED_UNICODE);
        }

        /* 验证投注号码格式是否正确 */
        $number = explode('[H]',trim($number,'[H]'));
        if( !empty($number) ){
            $total_money = 0;
            //查询当前彩种返点
            $lottery_info = Db::name('lottery_classify')->field('id,fandian')->where("czids REGEXP '(^|,){$czid}($|,)'")->find();
            if( empty($lottery_info) ){
                $ret['ResultMsg'] = '返点信息错误！';
                return json_encode($ret,JSON_UNESCAPED_UNICODE);
            }
            $fandian = floatval($lottery_info['fandian']);
            $save_data = [];
            $count = count($number);
            $theory_qh = $this->zhuihaoNext($czid,$count);
            foreach($number as $key=>$val){
                $detail = explode('[G]',$val);
                if( 10==count($detail)) {
                    if(!is_numeric($detail[2])) {
                        $ret['ResultMsg'] = '投注金额错误！';
                        return json_encode($ret,JSON_UNESCAPED_UNICODE);
                    }
                    //验证是否有效期号
                    $periods = $detail[9];
                    if( !in_array($periods,$theory_qh) ){
                        $ret['ResultMsg'] = '投注期号有误，请重新投注！';
                        $theory_qh = implode('|',$theory_qh).'---'.$periods;
                        $this->weigui_zhuihao($name,$number_original,$czid,$theory_qh,$from);
                        return json_encode($ret,JSON_UNESCAPED_UNICODE);
                    }
                    $total_money += floatval($detail[2]);
                    //查询验证所需信息
                    $checks = Db::name('play_classify_ext')->alias('a')
                        ->join('kkty_play_classify b','a.play_id=b.id','LEFT')
                        ->where(['a.play_id'=>$detail[7],'a.czid'=>$czid,'a.open'=>1])
                        ->field('a.peilv_ids,b.id,b.class_name_mini,b.min_num,b.max_num,b.max_money')
                        ->find();
                    if(empty($checks)){
                        $checks = Db::name('play_classify')->field('id,class_name_mini,min_num,max_num,peilv_ids,max_money')->where('id',$detail[7])->find();
                    }
                    //验证最大投注金额
                    if( $checks['max_money'] ) {
                        $pay_money = floatval($detail[4]);
                        if( '2'==$detail[1] ){
                            $pay_money = floatval($detail[4])/10;
                        }elseif( '3'==$detail[1] ){
                            $pay_money = floatval($detail[4])/100;
                        }
                        if( $pay_money > floatval($checks['max_money']) ){
                            $ret['ResultMsg'] = '超出单注最大投注金额';
                            return json_encode($ret,JSON_UNESCAPED_UNICODE);
                        }
                    }
                    //获取赔率信息
                    $pl_attr = explode('|',trim($detail[5],'|'));
                    $pl_id_attr = explode('|',trim($detail[8],'|'));

                    if( 173 == intval($detail[7]) ){
                        //正码过关
                        if( count($pl_attr) > 1 || empty($pl_attr) ){
                            $ret['ResultMsg'] = '赔率计算错误';
                            $this->weigui_zhuihao($name,$number_original,$czid,'赔率计算错误',$from);
                            return json_encode($ret,JSON_UNESCAPED_UNICODE);
                        }
                        $peilv_true = 1;
                        foreach($pl_id_attr as $k=>$v){
                            $peilv_info = Db::name('peilv')->find($v);
                            $peilv_tmp = $peilv_info['zdpl'] + ( ($peilv_info['zgpl']-$peilv_info['zdpl']) / ($fandian ? $fandian : 1) ) * ($fandian - $detail[6]);
                            $peilv_true *= $peilv_tmp;
                        }
                        if( sprintf('%.2f',$peilv_true) != sprintf('%.2f',$detail[5]) ) {
                            $ret['ResultMsg'] = '赔率计算错误';
                            $this->weigui_zhuihao($name,$number_original,$czid,'赔率计算错误',$from);
                            return json_encode($ret,JSON_UNESCAPED_UNICODE);
                        }
                    }elseif( 242 == intval($detail[7]) ){
                        //合肖
                        if( count($pl_attr) > 1 || empty($pl_attr) ){
                            $ret['ResultMsg'] = '赔率计算错误';
                            $this->weigui_zhuihao($name,$number_original,$czid,'赔率计算错误',$from);
                            return json_encode($ret,JSON_UNESCAPED_UNICODE);
                        }
                        $peilv_true = 0;
                        foreach($pl_id_attr as $k=>$v){
                            $peilv_info = Db::name('peilv')->find($v);
                            $peilv_tmp = $peilv_info['zdpl'] + ( ($peilv_info['zgpl']-$peilv_info['zdpl']) / ($fandian ? $fandian : 1) ) * ($fandian - $detail[6]);
                            $peilv_true += $peilv_tmp;
                        }
                        $peilv_true = $peilv_true / count($pl_id_attr) / count($pl_id_attr);
                        $peilv_true = sprintf('%.2f',$peilv_true);
                        if( sprintf('%.2f',$peilv_true) != sprintf('%.2f',$detail[5]) ) {
                            $ret['ResultMsg'] = '赔率计算错误';
                            $this->weigui_zhuihao($name,$number_original,$czid,'赔率计算错误',$from);
                            return json_encode($ret,JSON_UNESCAPED_UNICODE);
                        }
                    }elseif( 294==intval($detail[7]) || 295==intval($detail[7]) || 297==intval($detail[7]) || 298==intval($detail[7]) ){
                        if( count($pl_attr) !=count($pl_id_attr) || empty($pl_attr) ){
                            $ret['ResultMsg'] = '赔率计算错误';
                            $this->weigui_zhuihao($name,$number_original,$czid,'赔率计算错误',$from);
                            return json_encode($ret,JSON_UNESCAPED_UNICODE);
                        }
                        foreach($pl_attr as $k=>$v){
                            $pl_detail = explode(' ',trim($v));
                            $pl_id_detail = explode(' ',trim($pl_id_attr[$k]));
                            if( count($pl_detail) !=count($pl_id_detail) ){
                                $ret['ResultMsg'] = '赔率计算错误';
                                $this->weigui_zhuihao($name,$number_original,$czid,'赔率计算错误',$from);
                                return json_encode($ret,JSON_UNESCAPED_UNICODE);
                            }
                            foreach($pl_id_detail as $kk=>$value){
                                if( !empty($value) ){
                                    $peilv_info = Db::name('peilv')->where('id','like',$value)->find();
                                    if(empty($peilv_info)){
                                        $ret['ResultMsg'] = '赔率计算错误';
                                        $this->weigui_zhuihao($name,$number_original,$czid,'赔率计算错误',$from);
                                        return json_encode($ret,JSON_UNESCAPED_UNICODE);
                                    }
                                    $peilv_true = $peilv_info['zdpl'] + ( ($peilv_info['zgpl']-$peilv_info['zdpl']) / ($fandian ? $fandian : 1) ) * ($fandian - $detail[6]);
                                    $peilv_true = sprintf('%.2f',$peilv_true);
                                    if( $peilv_true != sprintf('%.2f',$pl_detail[$kk]) ) {
                                        $ret['ResultMsg'] = '赔率计算错误';
                                        $this->weigui_zhuihao($name,$number_original,$czid,'赔率计算错误',$from);
                                        return json_encode($ret,JSON_UNESCAPED_UNICODE);
                                    }
                                }
                            }
                        }
                    }else{
                        if( count($pl_attr) !=count($pl_id_attr) || empty($pl_attr) ){
                            $ret['ResultMsg'] = '赔率计算错误';
                            $this->weigui_zhuihao($name,$number_original,$czid,'赔率计算错误',$from);
                            return json_encode($ret,JSON_UNESCAPED_UNICODE);
                        }
                        foreach($pl_id_attr as $k=>$v){
                            $peilv_info = Db::name('peilv')->where('id','like',$v)->find();
                            if(empty($peilv_info)){
                                $ret['ResultMsg'] = '赔率计算错误';
                                $this->weigui_zhuihao($name,$number_original,$czid,'赔率计算错误',$from);
                                return json_encode($ret,JSON_UNESCAPED_UNICODE);
                            }
                            $peilv_true = $peilv_info['zdpl'] + ( ($peilv_info['zgpl']-$peilv_info['zdpl']) / ($fandian ? $fandian : 1) ) * ($fandian - $detail[6]);
                            $peilv_true = sprintf('%.2f',$peilv_true);
                            if( $peilv_true != sprintf('%.2f',$pl_attr[$k]) ) {
                                $ret['ResultMsg'] = '赔率计算错误';
                                $this->weigui_zhuihao($name,$number_original,$czid,'赔率计算错误',$from);
                                return json_encode($ret,JSON_UNESCAPED_UNICODE);
                            }
                        }
                    }
                    //验证号码是否超限
                    $code = array_map('trim',explode(',',$detail[0]));
                    if( 1==count($code) ){
                        if( is_numeric($code[0]) && (floatval($code[0])<$checks['min_num'] || floatval($code[0])>$checks['max_num'] ) && $checks['max_num'] >0 ){
                            $ret['ResultMsg'] = '号码超出可选范围';
                            $this->weigui_zhuihao($name,$number_original,$czid,'号码超出可选范围',$from);
                            return json_encode($ret,JSON_UNESCAPED_UNICODE);
                        }
                    }else{
                        foreach($code as $v) {
                            if( is_numeric($v) && (floatval($v)<$checks['min_num'] || floatval($v)>$checks['max_num'] ) && $checks['max_num'] >0 ){
                                $ret['ResultMsg'] = '号码超出可选范围';
                                $this->weigui_zhuihao($name,$number_original,$czid,'号码超出可选范围',$from);
                                return json_encode($ret,JSON_UNESCAPED_UNICODE);
                            }
                        }
                    }
                    //验证投注注数
                    $tzzs = touzhu_hm_code_zhushu($detail[7],$detail[0],$lottery_info['id']);
                    if( 0==$tzzs || $tzzs!=$detail[3] ){
                        $ret['ResultMsg'] = '验证投注注数失败';
                        $this->weigui_zhuihao($name,$number_original,$czid,'验证投注注数失败',$from);
                        return json_encode($ret,JSON_UNESCAPED_UNICODE);
                    }
                    array_push($detail,$checks['id']);
                    $save_data[] = $detail;

                }else{
                    $ret['ResultMsg'] = '数据格式错误';
                    return json_encode($ret,JSON_UNESCAPED_UNICODE);
                }
            }

            //验证投注总金额
            $total_theory = $this->calc_zh_money($number_original);
            if( 0==$total_theory ||sprintf("%.2f",$total_theory)!=sprintf("%.2f",$total_money) ){
                $ret['ResultMsg'] = '投注总额验证失败';
                $this->weigui_zhuihao($name,$number_original,$czid,'投注总额验证失败',$from);
                return json_encode($ret,JSON_UNESCAPED_UNICODE);
            }
            //验证用户总金额
            if($user['je'] < $total_money) {
                $ret['ResultMsg'] = '账户金额不足';
                return json_encode($ret,JSON_UNESCAPED_UNICODE);
            }
            Db::startTrans();
            try {
                foreach( $save_data as $kk=>$data ){
                    //限制返点范围
                    if($data[6] > $fandian) $data[6] = $fandian;
                    if($data[6] < 0) $data[6] = 0;

                    //返点应扣除金额
                    $fandian_je = floatval($data[2]) / 100 * floatval($data[6]);
//                  //计算返点、打码量、投注金额等信息
                    $touzhu_true_je = floatval($data[2]) - $fandian_je;
                    $user['je'] -= floatval( $touzhu_true_je );
                    $user['dml'] -= floatval( $touzhu_true_je );
                    $user['tzzje'] += floatval($touzhu_true_je);
                    $user['zyh_tzzje'] += floatval($touzhu_true_je);
                    //将新投注插入未结算列表
                    if( 0==$kk ){
                        $no_stop = 1==intval($isStop) ? 1 : 2;
                        if( !model( 'TouzhuListNo' )->setBetInfoNo($czid,$data[9],$data[0],$data[2],$data[4],$data[3],$name,$user['je'],0,0,$data[10],$data[5],$data[6],$fandian_je,0,0,$data[1],time(),$from,$no_stop) ){
                            throw new Exception("新投注插入未结算列表失败");
                        }
                    }else{
                        if( !model( 'TouzhuListZh' )->setBetInfoZh($czid,$data[9],$data[0],$data[2],$data[4],$data[3],$name,$user['je'],0,0,$data[10],$data[5],$data[6],$fandian_je,0,0,$data[1],time(),$from,$isStop) ){
                            throw new Exception("新投注插入未结算列表失败");
                        }
                    }
                }
                $user['dml'] < 0 && $user['dml'] = 0;
                if( !model('Username')->updateUserBetInfo($user['je'],$user['dml'],$user['tzzje'],$name,$user['zyh_tzzje']) ){
                    throw new Exception("更新用户信息失败");
                }
                Db::commit();
                $ret['result'] = 1;
                return json_encode($ret,JSON_UNESCAPED_UNICODE);
            } catch (\Exception $e) {
                Db::rollback();
                $ret['ResultMsg'] = '下注失败请重试';
                return json_encode($ret,JSON_UNESCAPED_UNICODE);
            }
        }else{
            $ret['ResultMsg'] = '数据格式错误';
            return json_encode($ret,JSON_UNESCAPED_UNICODE);
        }
    }
    public function lotteryZhuihao(){
        
        //参数    彩种id，彩种期号，投注期数
        $czid=input('czid','');
        $qihao = input('qihao','');
        $qishu = input('qishu','');
        $jine = input('jine',0);
        if(!$czid || !$qihao || !$qishu){
            return '参数缺失';
        }
        $qh =array('jine'=>$jine,'year'=>date('m-d'),'hour'=>date('H:i:s'),'datas'=>[]);
        $qh['datas'] = $this->zhuihaoNext_new($czid,$qishu);
        //unset($qh['datas'][0]);
        return json_encode($qh,JSON_UNESCAPED_UNICODE);
    }
    public function finishTime(){
        $list = Db::name("caipai_list")->column('id,cp_fp_time');
        $ret = array(
            'result'=>1,
            'datas' => $list
        );
        return json_encode($ret,JSON_UNESCAPED_UNICODE);
    }
    public function getNumber(){
        $wfid = input('wfid',0);
        $code = input("code",'');
        $label = input('label','');
        $class_id = 0;
        switch($label){
            case 'ks':
                $class_id = '3';
                break;
            case 'ssc':
                $class_id = '1';
                break;
            case 'lhc':
                $class_id = '8';
                break;
            default:
                $ret = array(
                    'result'=>0,
                );
                return json_encode($ret,JSON_UNESCAPED_UNICODE);

        }
        $tzzs = touzhu_hm_code_zhushu($wfid,$code,$class_id);
        $ret = array(
            'result'=>1,
            'datas' => $tzzs
        );
        return json_encode($ret,JSON_UNESCAPED_UNICODE);
    }
    public function randomCode(){
        $wfid = input("wfid",0);
        $time = input('time',1);
        $ret = [];
        for( $i=0; $i<$time; $i++ ){
            $ret[] = self::random($wfid);
        }
        $rets = array(
            'result'=>1,
            'datas' => $ret
        );
        return json_encode($rets,JSON_UNESCAPED_UNICODE);
    }
    private static function random($wfid){
        $ret = ['code'=>'','number'=>0];
        $label = 1;//默认时时彩
        switch( intval($wfid) ){
            case 1:
                //五星直选复式
            case 2:
                //五星直选组合
                $ret['code'] = implode(',',array(array_rand(self::$code),array_rand(self::$code),array_rand(self::$code),array_rand(self::$code),array_rand(self::$code)));
                break;
            case 3:
                //五星组选120
                $ret['code'] = implode( ' ', array_rand(self::$code,5));
                break;
            case 4:
                //五星组选60
                $code_0 = array_rand(self::$code);
                unset(self::$code[$code_0]);
                $code_1 = implode(" ",array_rand(self::$code,3));
                $ret['code'] = implode(",",array($code_0,$code_1));
                self::$code = [0,1,2,3,4,5,6,7,8,9];
                break;
            case 5:
                //五星组选30
                $code_0 = array_rand(self::$code,2);
                unset(self::$code[$code_0[0]],self::$code[$code_0[1]]);
                $code_0 = implode(" ",$code_0);
                $code_1 = array_rand(self::$code);
                $ret['code'] = implode(",",array($code_0,$code_1));
                self::$code = [0,1,2,3,4,5,6,7,8,9];
                break;
            case 6:
                //五星组选20
            case 12:
                //后四组选12
            case 18:
                //前四组选12
                $code_0 = array_rand(self::$code);
                unset(self::$code[$code_0]);
                $code_1 = implode(" ",array_rand(self::$code,2));
                $ret['code'] = implode(",",array($code_0,$code_1));
                self::$code = [0,1,2,3,4,5,6,7,8,9];
                break;
            case 7:
                //五星组选10
            case 8:
                //五星组选5
            case 14:
                //后四组选4
            case 20:
                //前四组选4
                $code_0 = array_rand(self::$code);
                unset(self::$code[$code_0]);
                $code_1 = array_rand(self::$code);
                $ret['code'] = implode(",",array($code_0,$code_1));
                self::$code = [0,1,2,3,4,5,6,7,8,9];
                break;
            case 9:
                //后四直选复式
            case 10:
                //后四直选组合
            case 15:
                //前四直选复式
            case 16:
                //前四直选组合
                $ret['code'] = implode(',',array(array_rand(self::$code),array_rand(self::$code),array_rand(self::$code),array_rand(self::$code)));
                break;
            case 11:
                //后四组选24
            case 17:
                //前四组选24
            case 65:
                //五星不定位五星四码
                $ret['code'] = implode( ' ', array_rand(self::$code,4));
                break;
            case 13:
                //后四组选6
            case 19:
                //前四组选6
            case 25:
                //后三组选组三
            case 31:
                //中三组选组三
            case 37:
                //前三组选组三
            case 43:
                //后二组选复式
            case 48:
                //前二组选复式
            case 53:
                //三星不定位后三二码
            case 54:
                //三星不定位中三二码
            case 55:
                //三星不定位前三二码
            case 58:
                //四星不定位前四二码
            case 59:
                //四星不定位后四二码
            case 63:
                //五星不定位五星二码
                $ret['code'] = implode( ' ', array_rand(self::$code,2));
                break;
            case 21:
                //后三直选复式
            case 27:
                //中三直选复式
            case 33:
                //前三直选复式
                $ret['code'] = implode(',',array(array_rand(self::$code),array_rand(self::$code),array_rand(self::$code)));
                break;
            case 22:
                //后三直选和值
            case 28:
                //中三直选和值
            case 34:
                //前三直选和值
                $ret['code'] = array_rand(self::$code_sum);
                break;
            case 23:
                //后三直选跨度
            case 24:
                //后三直选和值尾数
            case 29:
                //中三直选跨度
            case 30:
                //中三直选和值尾数
            case 35:
                //前三直选跨度
            case 36:
                //前三直选和值尾数
            case 41:
                //后二直选跨度
            case 42:
                //后二直选和值尾数
            case 46:
                //前二直选跨度
            case 47:
                //前二直选和值尾数
            case 50:
                //三星不定位后三一码
            case 51:
                //三星不定位中三一码
            case 52:
                //三星不定位前三一码
            case 56:
                //四星不定位前四一码
            case 57:
                //四星不定位后四一码
            case 62:
                //五星不定位五星一码
            case 72:
                //趣味一帆风顺
            case 73:
                //趣味好事成双
            case 74:
                //趣味三星报喜
            case 75:
                //趣味四季发财
                $ret['code'] = array_rand(self::$code);
                break;
            case 26:
                //后三组选组六
            case 32:
                //中三组选组六
            case 38:
                //前三组选组六
            case 60:
                //四星不定位前四三码
            case 61:
                //四星不定位后四三码
            case 64:
                //五星不定位五星三码
                $ret['code'] = implode( ' ', array_rand(self::$code,3));
                break;
            case 39:
                //后二直选复式
            case 44:
                //前二直选复式
                $ret['code'] = implode(',',array(array_rand(self::$code),array_rand(self::$code)));
                break;
            case 40:
                //后二直选和值
            case 45:
                //前二直选和值
                $ret['code'] = array_rand(self::$code_sum2);
                break;
            case 49:
                //定位胆
            case 296:
                //数字盘
                $level = rand(0,4);
                $between = [];
                for( $i=0; $i<5; $i++ ){
                    $between[] = $i==$level ? array_rand(self::$code): '';
                }
                $ret['code'] = implode(',',$between);
                break;
            case 66:
                //任二复式
                $level_attr = array_rand([0,1,2,3,4],2);
                $between = [];
                for( $i=0; $i<5; $i++ ){
                    $between[] = in_array($i,$level_attr) ? array_rand(self::$code): '';
                }
                $ret['code'] = implode(',',$between);
                break;
            case 67:
                //任二组选
                $position_attr = array_rand(self::$code_position,2);
                $code_0 = implode(" ",array(self::$code_position[$position_attr[0]],self::$code_position[$position_attr[1]]));
                $code_1 = implode(" ",array_rand(self::$code,2));
                $ret['code'] = implode(',',array($code_0,$code_1));
                break;
            case 68:
                //任三复式
                $level_attr = array_rand([0,1,2,3,4],3);
                $between = [];
                for( $i=0; $i<5; $i++ ){
                    $between[] = in_array($i,$level_attr) ? array_rand(self::$code): '';
                }
                $ret['code'] = implode(',',$between);
                break;
            case 69:
                //任三组三
                $position_attr = array_rand(self::$code_position,3);
                $code_0 = implode(" ",array(self::$code_position[$position_attr[0]],self::$code_position[$position_attr[1]],self::$code_position[$position_attr[2]]));
                $code_1 = implode(" ",array_rand(self::$code,2));
                $ret['code'] = implode(',',array($code_0,$code_1));
                break;
            case 70:
                //任三组六
                $position_attr = array_rand(self::$code_position,3);
                $code_0 = implode(" ",array($position_attr[0],self::$code_position[$position_attr[1]],self::$code_position[$position_attr[2]]));
                $code_1 = implode(" ",array_rand(self::$code,3));
                $ret['code'] = implode(',',array($code_0,$code_1));
                break;
            case 71:
                //任四复式
                $level_attr = array_rand([0,1,2,3,4],4);
                $between = [];
                for( $i=0; $i<5; $i++ ){
                    $between[] = in_array($i,$level_attr) ? array_rand(self::$code): '';
                }
                $ret['code'] = implode(',',$between);
                break;
            case 76:
                //龙虎万千
            case 77:
                //龙虎万百
            case 78:
                //龙虎万十
            case 79:
                //龙虎万个
            case 80:
                //龙虎千百
            case 81:
                //龙虎千十
            case 82:
                //龙虎千个
            case 83:
                //龙虎百十
            case 84:
                //龙虎百个
            case 85:
                //龙虎十个
                $position_attr = array_rand(self::$code_model,1);
                $ret['code'] = self::$code_model[$position_attr];
                break;
            case 86:
                //大小单双总和
            case 87:
                //定位万位
            case 88:
                //定位千位
            case 89:
                //定位百位
            case 90:
                //定位十位
            case 91:
                //定位个位
                $position_attr = array_rand(self::$code_model2,1);
                $ret['code'] = self::$code_model2[$position_attr];
                break;
            case 92:
                //大小单双串关
                $level_attr = array_rand([0,1,2,3,4],1);
                $between = [];
                for( $i=0; $i<5; $i++ ){
                    if( $i==$level_attr ){
                        $between[] = self::$code_model2[array_rand(self::$code_model2)];
                    }else{
                        $between[] = '';
                    }
                }
                $ret['code'] = implode(',',$between);
                break;
            case 93:
                //特殊号前三
            case 94:
                //特殊号中三
            case 95:
                //特殊号后三
                $position_attr = array_rand(self::$code_model3,1);
                $ret['code'] = self::$code_model3[$position_attr];
                break;
            case 96:
                //斗牛
                $position_attr = array_rand(self::$code_model4,1);
                $ret['code'] = self::$code_model4[$position_attr];
                break;
            case 163:
                //六合彩两面
                $position_attr = array_rand(self::$lhc_sum,1);
                $ret['code'] = self::$lhc_sum[$position_attr];
                $label = 8;
                break;
            case 165:
                //六合彩正码A
            case 291:
                //六合彩正码B
                $position_attr = array_rand(self::$lhc_code,1);
                $ret['code'] = self::$lhc_code[$position_attr];
                $label = 8;
                break;
            case 166:
                //正一特
            case 167:
                //正二特
            case 168:
                //正三特
            case 169:
                //正四特
            case 170:
                //正五特
            case 171:
                //正六特
                $position_attr = array_rand(self::$lhc_code_square,1);
                $ret['code'] = self::$lhc_code_square[$position_attr];
                $label = 8;
                break;
            case 164:
                //特码B
                $position_attr = array_rand(self::$lhc_code_spec_b,1);
                $ret['code'] = self::$lhc_code_spec_b[$position_attr];
                $label = 8;
                break;
            case 289:
                //特码A
                $position_attr = array_rand(self::$lhc_code_spec,1);
                $ret['code'] = self::$lhc_code_spec[$position_attr];
                $label = 8;
                break;
            case 172:
                //正码1-6
                $position0 = array_rand(self::$lhc_zm,1);
                $code_0 = self::$lhc_zm[$position0];
                $position1 = array_rand(self::$lhc_zm_code,1);
                $code_1 = self::$lhc_zm_code[$position1];
                $ret['code'] = $code_0.'_'.$code_1;
                $label = 8;
                break;
            case 173:
                //正码过关
                $label = 8;
                $level_attr = array_rand([0,1,2,3,4,5],2);
                $code = array();
                for( $i=0; $i<6; $i++ ){
                    if( in_array($i,$level_attr) ){
                        $position = array_rand(self::$lhc_zm_code2,1);
                        $code[] = self::$lhc_zm_code2[$position];
                    }else{
                        $code[] = ' ';
                    }
                }
                $ret['code'] = implode(',',$code);
                break;
            case 174:
                //四全中
                $position_attr = array_rand(self::$lhc_code,4);
                $ret['code'] = self::$lhc_code[$position_attr[0]].' '.self::$lhc_code[$position_attr[1]].' '.self::$lhc_code[$position_attr[2]].' '.self::$lhc_code[$position_attr[3]];
                $label = 8;
                break;
            case 181:
                //三全中
            case 188:
                //三中二
                $position_attr = array_rand(self::$lhc_code,3);
                $ret['code'] = self::$lhc_code[$position_attr[0]].' '.self::$lhc_code[$position_attr[1]].' '.self::$lhc_code[$position_attr[2]];
                $label = 8;
                break;
            case 195:
                //二全中
            case 204:
                //二中特
            case 213:
                //特串
                $position_attr = array_rand(self::$lhc_code,2);
                $ret['code'] = self::$lhc_code[$position_attr[0]].' '.self::$lhc_code[$position_attr[1]];
                $label = 8;
                break;
            case 222:
                //二肖连
                $position_attr = array_rand(self::$lhc_sx,2);
                $ret['code'] = self::$lhc_sx[$position_attr[0]].' '.self::$lhc_sx[$position_attr[1]];
                $label = 8;
                break;
            case 223:
                //三肖连
                $position_attr = array_rand(self::$lhc_sx,3);
                $ret['code'] = self::$lhc_sx[$position_attr[0]].' '.self::$lhc_sx[$position_attr[1]].' '.self::$lhc_sx[$position_attr[2]];
                $label = 8;
                break;
            case 224:
                //四肖连
                $position_attr = array_rand(self::$lhc_sx,4);
                $ret['code'] = self::$lhc_sx[$position_attr[0]].' '.self::$lhc_sx[$position_attr[1]].' '.self::$lhc_sx[$position_attr[2]].' '.self::$lhc_sx[$position_attr[3]];
                $label = 8;
                break;
            case 225:
                //五肖连
                $position_attr = array_rand(self::$lhc_sx,5);
                $ret['code'] = self::$lhc_sx[$position_attr[0]].' '.self::$lhc_sx[$position_attr[1]].' '.self::$lhc_sx[$position_attr[2]].' '.self::$lhc_sx[$position_attr[3]].' '.self::$lhc_sx[$position_attr[4]];
                $label = 8;
                break;
            case 226:
                //二连尾
                $ret['code'] = implode(' ',array_rand(self::$code,2));
                $label = 8;
                break;
            case 227:
                //三连尾
                $ret['code'] = implode(' ',array_rand(self::$code,3));
                $label = 8;
                break;
            case 228:
                //四连尾
                $ret['code'] = implode(' ',array_rand(self::$code,4));
                $label = 8;
                break;
            case 229:
                //五连尾
                $ret['code'] = implode(' ',array_rand(self::$code,5));
                $label = 8;
                break;
            case 230:
                //五不中
            case 258:
                //五中一
                $attr = array_rand(self::$lhc_code,5);
                $map = array_map(function($v){
                    $val = intval($v)+1;
                    return $val<10 ? '0'.$val: $val;
                },$attr);
                $ret['code'] = implode(' ',$map);
                $label = 8;
                break;
            case 231:
                //六不中
            case 259:
                //六中一
                $attr = array_rand(self::$lhc_code,6);
                $map = array_map(function($v){
                    $val = intval($v)+1;
                    return $val<10 ? '0'.$val: $val;
                },$attr);
                $ret['code'] = implode(' ',$map);
                $label = 8;
                break;
            case 232:
                //七不中
            case 260:
                //七中一
                $attr = array_rand(self::$lhc_code,7);
                $map = array_map(function($v){
                    $val = intval($v)+1;
                    return $val<10 ? '0'.$val: $val;
                },$attr);
                $ret['code'] = implode(' ',$map);
                $label = 8;
                break;
            case 233:
                //八不中
            case 261:
                //八中一
                $attr = array_rand(self::$lhc_code,8);
                $map = array_map(function($v){
                    $val = intval($v)+1;
                    return $val<10 ? '0'.$val: $val;
                },$attr);
                $ret['code'] = implode(' ',$map);
                $label = 8;
                break;
            case 234:
                //九不中
            case 262:
                //九中一
                $attr = array_rand(self::$lhc_code,9);
                $map = array_map(function($v){
                    $val = intval($v)+1;
                    return $val<10 ? '0'.$val: $val;
                },$attr);
                $ret['code'] = implode(' ',$map);
                $label = 8;
                break;
            case 235:
                //十不中
            case 263:
                //十中一
                $attr = array_rand(self::$lhc_code,10);
                $map = array_map(function($v){
                    $val = intval($v)+1;
                    return $val<10 ? '0'.$val: $val;
                },$attr);
                $ret['code'] = implode(' ',$map);
                $label = 8;
                break;
            case 236:
                //十一不中
                $attr = array_rand(self::$lhc_code,11);
                $map = array_map(function($v){
                    $val = intval($v)+1;
                    return $val<10 ? '0'.$val: $val;
                },$attr);
                $ret['code'] = implode(' ',$map);
                $label = 8;
                break;
            case 237:
                //十二不中
                $attr = array_rand(self::$lhc_code,12);
                $map = array_map(function($v){
                    $val = intval($v)+1;
                    return $val<10 ? '0'.$val: $val;
                },$attr);
                $ret['code'] = implode(' ',$map);
                $label = 8;
                break;
            case 238:
                //正肖
            case 239:
                //特肖
            case 240:
                //一肖
            case 242:
                //合肖
                $position_attr = array_rand(self::$lhc_sx);
                $ret['code'] = self::$lhc_sx[$position_attr];
                $label = 8;
                break;
            case 241:
                //总肖
                $position_attr = array_rand(self::$lhc_sx2);
                $ret['code'] = self::$lhc_sx2[$position_attr];
                $label = 8;
                break;
            case 250:
                //三色波
                $position_attr = array_rand(self::$lhc_ssb);
                $ret['code'] = self::$lhc_ssb[$position_attr];
                $label = 8;
                break;
            case 251:
                //半波
                $position_attr = array_rand(self::$lhc_bb);
                $ret['code'] = self::$lhc_bb[$position_attr];
                $label = 8;
                break;
            case 252:
                //半半波
                $position_attr = array_rand(self::$lhc_bbb);
                $ret['code'] = self::$lhc_bbb[$position_attr];
                $label = 8;
                break;
            case 253:
                //七色波
                $position_attr = array_rand(self::$lhc_qsb);
                $ret['code'] = self::$lhc_qsb[$position_attr];
                $label = 8;
                break;
            case 254:
                //头尾数
                $position_attr = array_rand(self::$lhc_tws);
                $ret['code'] = self::$lhc_tws[$position_attr];
                $label = 8;
                break;
            case 255:
                //正特尾数
                $position_attr = array_rand(self::$lhc_ztws);
                $ret['code'] = self::$lhc_ztws[$position_attr];
                $label = 8;
                break;
            case 256:
                //七码
                $position_attr = array_rand(self::$lhc_qm);
                $ret['code'] = self::$lhc_qm[$position_attr];
                $label = 8;
                break;
            case 257:
                //五行
                $position_attr = array_rand(self::$lhc_wx);
                $ret['code'] = self::$lhc_wx[$position_attr];
                $label = 8;
                break;
            case 297:
                //两面盘
                $level_attr = array_rand([0,1,2,3,4,5],1);
                $code = array();
                for( $i=0; $i<6; $i++ ){
                    if( $i==$level_attr ){
                        if( 0==$i ){
                            $bet = array_merge(self::$code_model,self::$code_model2);
                            $code[] = $bet[array_rand($bet)];
                        }else{
                            $code[] = self::$code_model2[array_rand(self::$code_model2)];
                        }
                    }else{
                        $code[] = '';
                    }
                }
                $ret['code'] = implode(',',$code);
                break;
            case 298:
                //时时彩 前中后
                $level_attr = array_rand([0,1,2],1);
                $code = array();
                for( $i=0; $i<3; $i++ ){
                    if( $i==$level_attr ){
                        $code[] = self::$code_model3[array_rand(self::$code_model3)];
                    }else{
                        $code[] = '';
                    }
                }
                $ret['code'] = implode(',',$code);
                break;
            default:
                return $ret;
        }
        $ret['code'] = strval($ret['code']);
        $ret['number'] = touzhu_hm_code_zhushu($wfid,$ret['code'],$label);
        return $ret;
    }
    private static function lhcTimeList($time,$qh,$fp_time){
        $calc_time = strtotime('+1 day',$time);
        $week = date("w", $calc_time);
        if ($week == '2' || $week == '4' || $week == '0') {   //星期2,4 日+2天
            $data['jztime'] = strtotime(date('Y-m-d', $calc_time + 2 * 24 * 3600) . ' 21:30:00') - $fp_time;
        }
        if ($week == '6') {   //星期6+3天
            if((11==intval(date('m',$calc_time)) && 10==intval(date('d',$calc_time))) || (12==intval(date('m',$calc_time)) && 29==intval(date('d',$calc_time)))){
                $data['jztime'] = strtotime(date('Y-m-d', $calc_time + 1 * 24 * 3600) . ' 21:30:00') - $fp_time;
            }else{
                $data['jztime'] = strtotime(date('Y-m-d', $calc_time + 3 * 24 * 3600) . ' 21:30:00') - $fp_time;
            }
        }
        if ($week == '1' || $week == '3' || $week == '5') {   //星期1,3,5+1天
            $data['jztime'] = strtotime(date('Y-m-d', $calc_time + 1 * 24 * 3600) . ' 21:30:00') - $fp_time;
        }
        $data['qihao'] = strval( intval($qh)+1 );
        return $data;
    }
}